export const echartMoreLine = {
  data () {
    return {
      colorg: ['rgb(0,108,237)', 'rgb(0,207,255)', 'rgb(0,255,255)', 'rgb(6,253,188)']
    }
  },
  created () {
  },
  mounted () {
    this.initChart()
  },
  beforeDestroy () {
    window.removeEventListener('resize', () => {
      this.chartInstance.resize()
    })
  },
  methods: {
    timeWay (arrBig) {
      for (var i = 1; i < arrBig.length; i++) {
        arrBig[i][0] = arrBig[i][0].substring(5, arrBig[i][0].length - 3)
      }
    },
    initChart () {
      this.initOption = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            lineStyle: {
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: 'rgba(0, 255, 233,0)'
                  },
                  {
                    offset: 0.5,
                    color: 'rgba(255, 255, 255,1)'
                  },
                  {
                    offset: 1,
                    color: 'rgba(0, 255, 233,0)'
                  }
                ],
                global: false
              }
            }
          }
        },
        legend: {
          top: '4%',
          itemWidth: 15,
          itemHeight: 8,
          textStyle: {
            color: '#a6bde9',
            fontSize: 10
          }
        },
        grid: {
          top: '15%',
          left: '6%',
          right: '5%',
          bottom: '0%',
          containLabel: true
        },
        toolbox: {
          show: true,
          feature: {
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          axisTick: { // 不显示轴刻度
            show: false
          },
          splitLine: {
            show: false
          },
          axisLine: {
            lineStyle: {
              color: '#a6bde9'
            }
          },
          axisLabel: {
            interval: 'auto',
            formatter: function (value) {
              let ret = '' // 拼接加\n返回的类目项
              var maxLength = 6 // 每行最多个数
              var valLength = value.length // x轴一个项的总数
              var rowN = Math.ceil(valLength / maxLength)
              if (rowN > 1) { // 如果大于5个字符
                for (let i = 0; i < rowN; i++) {
                  let temp = ''
                  temp = value.substring(i * maxLength, i * maxLength + maxLength) + '\n'
                  ret += temp
                }
                return ret
              } else {
                return value
              }
            },
            textStyle: {
              fontSize: 8
            }
          }
        },
        yAxis: [
          {
            name: '风机频率(hz)',
            nameTextStyle: {
              color: 'rgb(154, 170, 203)'
            },
            type: 'value',
            axisLabel: {
              interval: 'auto',
              formatter: '{value}',
              color: 'rgb(154, 170, 203)'
            },
            axisTick: { // 不显示轴刻度
              show: false
            },
            min: 'dataMin',
            max: 'dataMax', // y轴范围
            splitLine: { // 属于y轴的是grid横线
              show: false,
              lineStyle: {
                type: 'dashed'
              }
            }
          }
        ],
        dataset: {
          source: []
        },
        series: []
      }
      // console.log('this.$refs.echartsPoly', this.$refs.echartsPoly)
      this.chartInstance = this.$echarts.init(this.$refs.echartsPoly)
      this.chartInstance.setOption(this.initOption)
      this.echartsResize()
    },
    echartsResize () {
      window.addEventListener('resize', () => {
        this.chartInstance.resize()
      })
    }
  }
}
